from langchain_openai import ChatOpenAI
from pydantic import SecretStr

from settings import DASHSCOPE_API_KEY

# 1-定义客户端
llm = ChatOpenAI(
    model="qwen-max",
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    api_key=SecretStr(DASHSCOPE_API_KEY),
    streaming=True
)

# 2-定义对话上下文
messages = [
    {"role": "system", "content": "You are a helpful assistant! Your name is Bob."},
    {"role": "user", "content": "你是谁？"},
]
print("----chat_prompt_message:", messages)

# 3-打印
print("-----Hold on, LLM 正在回答！-----")
response = llm.invoke(messages)
print("----response:", response)
